package com.zld.smarket.service.serviceImpl;

import com.zld.smarket.dao.ShelvesdownMapper;
import com.zld.smarket.dto.ShelvesdownList;
import com.zld.smarket.dto.ShelvesonList;
import com.zld.smarket.pojo.Shelvesdown;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.ShelvesdownService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShelvesdownServiceImpl implements ShelvesdownService {
    @Autowired
    private ShelvesdownMapper shelvesdownMapper;
    @Override
    public ResponseData findList(Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }
        List<ShelvesdownList> shelvesdownLists = shelvesdownMapper.selectAllAndPage(page,limit);
        Long count = shelvesdownMapper.countShelvesdown();
        return new ResponseData(shelvesdownLists,count);
    }

    @Override
    public Long selectbyno(Long i) {
        return shelvesdownMapper.selectbyno(i);
    }

    @Override
    public Integer setshelvesdown(Shelvesdown shelvesdown) {
        int j=0;
        j=shelvesdownMapper.insert(shelvesdown);
        return j;
    }

    @Override
    public ResponseData search(String s, Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }

        List<ShelvesdownList> shelvesdownLists =  shelvesdownMapper.search(s,page,limit);
        Long count = shelvesdownMapper.countShelvesdown();
        return new ResponseData(shelvesdownLists,count);
    }

    @Override
    public Long totaldown() {
        return shelvesdownMapper.countTotaldown();
    }
}
